package com.light.common.base;

import com.light.common.base.BaseService;
import com.light.common.base.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * @Author YHR
 * @Date 2021/2/8 10:21
 * @Version 1.0
 */
@Component
public abstract class BaseController<T,K extends BaseService> {

    @Autowired
    private K baseService;

    @ApiOperation("新增操作")
    @PostMapping("")
    public ResponseResult save(@RequestBody T t){
        baseService.save(t);
        return ResponseResult.success();
    }

    @ApiOperation("更新操作")
    @PutMapping("")
    public ResponseResult update(@RequestBody T t){
        baseService.update(t);
        return ResponseResult.success();
    }

    @ApiOperation("获取详细信息")
    @GetMapping("/{id}")
    public ResponseResult<T> get(@PathVariable("id") Serializable id){
        return ResponseResult.success(baseService.get(id));
    }

    @ApiOperation("删除操作")
    @DeleteMapping("/delete")
    public ResponseResult remove(Serializable menuId){
        baseService.remove(menuId);
        return ResponseResult.success();
    }


    @ApiOperation("批量删除操作")
    @DeleteMapping("/batchRemove")
    public ResponseResult batchRemove(List<Serializable> menuIds){
        baseService.batchRemove(menuIds);
        return ResponseResult.success();
    }
}
